// import { Cat, PositionGroup, PresetPointData } from "./Cat";
// import { App } from "./app";
///<reference path='./Cat.ts'/>
///<reference path='./app.ts'/>

class Brush extends lg.Container {
    public _skin: lg.Sprite;
    private _t: TweenMax;
    private _normalSS: lg.SpriteSheet;
    private _mss: lg.SpriteSheet;
    private _lastV: boolean = false;
    private _tweenH:TweenMax;
    private _tweenW:TweenMax;
    private _skinContainer:lg.Container;
    constructor() {
        super();
        this.addEventListener("added", this.addedHandler);
    }
    private addedHandler(e) {
        e.target.removeEventListener("added", e.target.addedHandler);
        e.target.initView();
    }
    private startH()
    {
        this._tweenW.pause();
        //  this._skinContainer.x=10;
        //  this._skinContainer.y=0;
         this._tweenH.resume();
    }
     private startW()
    {
        
        this._tweenH.pause();
        //  this._skinContainer.x=0;
        //  this._skinContainer.y=10;
         this._tweenW.resume();
    }
    private stopTween()
    {
        this._tweenH.pause();
        this._tweenW.pause();
    }
    private initView() {
        this._skinContainer=new lg.Container()
        this._normalSS = new lg.SpriteSheet({ images: ["../res/assets/images/brush_animation.png"], frames: [[0, 0, 270, 54, 0, 20, 25], [0, 54, 271, 55, 0, 20, 26], [0, 109, 270, 54, 0, 20, 25], [0, 54, 271, 55, 0, 20, 26]] });
        this._skin = new lg.Sprite(this._normalSS);
        
        this._skin.stop();
        this._skin.framerate = 6;
        this.addChild(this._skinContainer);
        this._skinContainer.addChild(this._skin);
       
        this._tweenH = TweenMax.to(this._skinContainer, 0.5, { x: -10, repeat: -1, yoyo: true, ease: Linear.easeNone, onComplete: () => {
             } });

       this._tweenW = TweenMax.to(this._skinContainer, 0.5, { y: -10, repeat: -1, yoyo: true, ease: Linear.easeNone, onComplete: () => {
             } });

        setInterval(
            () => {
                // console.log("change")
                this._lastV = !this._lastV
                this.setMSkin(this._lastV);
                this._skin.play();
            }
        );
        this.yoyo(false);
        this._mss = new lg.SpriteSheet({ images: ["../res/assets/images/brushM.png"], frames: [[0, 0, 272, 80, 0, 18, 10.05], [0, 0, 272, 80, 0, 18, 10.05]] });
    }
    public setMSkin(v: boolean): void {
       
switch (App.lasetPositionGroup) {
            case PositionGroup.t0:
                this._skin.spriteSheet = this._normalSS;
                this.rotation = 0;
                this._skin.y = 18;
                this.startW();
                break;
            case PositionGroup.t1:
             this.startH();
                this._skin.spriteSheet = this._normalSS;
                this._skin.rotation = 90;
                this._skin.y = 0;
                this._skin.scaleX = 1;
                
//              this._skin.spriteSheet = this._normalSS;
//              this._skin.rotation = 90;
//              this._skin.y = 0;
//              this._skin.scaleX = 1;
                break;
            case PositionGroup.t2:
             this.startW();
                this._skin.spriteSheet = this._normalSS;
                this.rotation = 180;
                this._skin.y = -3;
                break;
            case PositionGroup.t3:
                this._skin.spriteSheet = this._normalSS;
                this.rotation = 180;
                this._skin.y = -2;
                break;
            case PositionGroup.t4:
               
                this._skin.spriteSheet = this._mss;
                this._skin.rotation = -85;
                this._skin.y = 0;
                this._skin.scaleX = 1;

                break;
            case PositionGroup.t5:
                this._skin.spriteSheet = this._mss;
                this.rotation = 70;
                this._skin.y = 4;
                this._skin.scaleX = -1;
                break;
                //
            case PositionGroup.t6:
                this._skin.spriteSheet = this._mss;
                this.rotation = 0;
                this._skin.y = 4;
                this._skin.scaleX = -1;
                break;
            case PositionGroup.t7:
                this._skin.spriteSheet = this._mss;
                this.rotation = -25;
                this._skin.y = 2;
                this._skin.scaleX = -1;
                break;
                //
            case PositionGroup.t8:
                this._skin.spriteSheet = this._mss;
                this.rotation = 80;
                this._skin.scaleX = 1;
                this._skin.y = 10;
                break;
                //
            case PositionGroup.t9:
                this._skin.spriteSheet = this._mss;
                this._skin.rotation = -8;
                this._skin.y = 0;
                this._skin.scaleX = 1;
            


                break;
                //
            case PositionGroup.d0:
                this._skin.spriteSheet =this._normalSS;
                this.rotation = 180;
                this._skin.y = -3;
                this._skin.scaleX = -1;
                break;
            case PositionGroup.d1:
                this._skin.spriteSheet = this._normalSS;
                this._skin.y = -3;
                this.rotation = 180;
                this._skin.scaleX = -1;
                break;
            case PositionGroup.d2:
                this._skin.spriteSheet = this._mss;
                this._skin.rotation = -90;
                this._skin.y = 0;
                this._skin.scaleX = -1;
                break;
            case PositionGroup.d3:
                this._skin.spriteSheet = this._mss;
                this._skin.y = 14;
                this._skin.scaleX = 1;
                this.rotation = 5;
                break;
            case PositionGroup.d4:
                this._skin.spriteSheet = this._mss;
                this._skin.scaleX = 1;
                this._skin.y = -3;
                this.rotation = 60;
                break;
                //
            case PositionGroup.d5:
                this._skin.spriteSheet = this._mss;
                this._skin.rotation = 20;
                this._skin.y = -3;
                this._skin.scaleX = 1;
                break;
            default:
        }
    }

    public yoyo(v: boolean) {
        if (this._t)
            v ? this._t.play() : this._t.pause();
    }
}